/**
 * Created by mj on 2017/3/30.
 */
$(function () {
    $('#organizationList').treegrid({
        url:"queryAll",
        idField:'id',
        treeField:'organizationName',
        checkbox:true,
        cascadeCheck:false,
        width:400,
        rownumbers:true,
        fit:true,
        columns:[[
            {field:'organizationName',title:'名 称',width:180,align:'center'},
            {field:'organizationDescription',title:'描 述',width:200,align:'center'}
        ]],
        toolbar: [
            { text: '增加部门', iconCls: 'icon-add', handler: function () { addNode(); } }, '-',
            { text: '修改部门', iconCls: 'icon-edit', handler: function () { editNode(); } }, '-',
            { text: '删除部门', iconCls: 'icon-remove', handler: function () { deleteNode(); }}, '-',
            { text: '刷新部门', iconCls: 'icon-reload', handler: function () {  $("#organizationList").treegrid("reload"); } }, '-',],
    });
});
function addNode() {
    var selRows = $("#organizationList").treegrid('getSelected');
    var ids ="" ;
    if (selRows == null || selRows == "") {
        $.messager.alert("提示", "请选择一个节点!");
    }else {
        // $.messager.alert("sdfsd",selRows.id);
        $("#organization_pid").val(selRows.id);
        $("#addOrganizationWin").show().window("open");
    }
}
function editNode() {
    var selRows = $("#organizationList").treegrid('getChecked');
    if (selRows == null || selRows == "") {
        $.messager.alert("提示", "请选择一个节点!");

    }else {
        $.messager.prompt('提示信息', '为了系统安全，请输入您的开发者凭证：', function(r){
            if (r){
                alert('你的姓名是：' + r);
            }
        });


    }
}
function deleteNode() {
    var node = $('#organizationList').treegrid('getChecked');
    alert(node);
    /*if (node == null || node == "") {
     $.messager.alert("提示", "请选择一个节点!");
     return;
     }*/
}